<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
// import resize from "./mixins/resize";
export default {
  // mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "370px",
    },
    selCompanyDataAuditList: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  // created() {
  //   this.initChart();
  // },
  watch: {
    selCompanyDataAuditList(newVal, oldVal) {
      if (newVal.length > 0) {
        this.initChart();
      }
    },
  },
  computed: {
    selCompanyDataAudit() {
      return this.selCompanyDataAuditList.map((item) => ({
        name: item.name,
        value: item.count,
      }));
    },
  },
  mounted() {
    this.initChart();
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");
      const that = this;
      this.chart.setOption({
        title: {
          text: "认证企业分布",
          textStyle: {
            color: "#333", // 字体颜色设置为黑色
            fontWeight: "bold", // 加粗字体
          },
          left: "center",
        },
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)",
        },
        series: [
          {
            name: "认证企业",
            type: "pie",
            roseType: "radius",
            radius: [25, 95],
            radius: ["40%", "75%"],
            data: this.selCompanyDataAudit,
          },
        ],
        color: ["#48a1fd", "#f0637b"],
      });
    },
  },
};
</script>

<style scoped></style>
